package alg20241116;

public class Text {
    public void sortColors(int[] nums) {
        int n = nums.length;
        for (int i = 0, left = -1, right = n; i < right;) {
            if(nums[i] == 0) swap(++left , i++, nums);
            else if(nums[i] == 1) i++;
            else swap(--right, i, nums);
        }
    }
    private static void swap(int i, int j, int[] nums){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}
